package smartgit;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.jetbrains.annotations.NotNull;

public final class alW
{
  private static final Map jdField_a_of_type_JavaUtilMap = new HashMap();
  private final ajB jdField_a_of_type_SmartgitAjB;
  private final ajB b;
  private final boolean jdField_a_of_type_Boolean;

  public static String a()
  {
    return "Signature";
  }

  public static String b()
  {
    return "java.awt.event.KeyEvent".substring(15, 18);
  }

  public static byte[] a(MessageDigest paramMessageDigest, int paramInt)
  {
    byte[] arrayOfByte1 = new byte[paramInt];
    byte[] arrayOfByte2 = paramMessageDigest.digest();
    int i = Math.min(arrayOfByte1.length, arrayOfByte2.length);
    for (int j = 0; j < i; j++) {
      arrayOfByte1[j] = arrayOfByte2[j];
    }
    int tmp44_43 = 0; byte[] tmp44_42 = arrayOfByte1;tmp44_42[tmp44_43] = ((byte)(tmp44_42[tmp44_43] & 0x7F)); int
      tmp53_52 = 0; byte[] tmp53_51 = arrayOfByte1;tmp53_51[tmp53_52] = ((byte)(tmp53_51[tmp53_52] | 0x40));
    return arrayOfByte1;
  }

  public static void a(ajB paramajB, MessageDigest paramMessageDigest)
  {
    byte[] arrayOfByte1 = paramajB.a();
    byte[] arrayOfByte2 = a(paramMessageDigest, 16);

    int i = Math.min(arrayOfByte1.length, arrayOfByte2.length);
    for (int j = 0; j < i; j++) {
      if (arrayOfByte1[j] != arrayOfByte2[j]) {
        throw new alT();
      }
    }
  }

  public static MessageDigest a()
  {
    try
    {
      return MessageDigest.getInstance("byte".substring(0, 3).replace('b', 'S').replace('y', 'H').replace('t', 'A'));
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new alS(localNoSuchAlgorithmException);
    }
  }

  public static BufferedReader a(InputStream paramInputStream)
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    a(paramInputStream, localByteArrayOutputStream);

    byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();
    String str = a(arrayOfByte);
    return a(arrayOfByte, str);
  }

  public static BufferedReader a(byte[] paramArrayOfByte, String paramString)
  {
    alV localalV;
    try
    {
      localalV = new alV(new InputStreamReader(new ByteArrayInputStream(paramArrayOfByte), paramString));
      localalV.a("#");
      localalV.b(true);
      localalV.a(true);
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      throw new RZ(localUnsupportedEncodingException);
    }
    return localalV;
  }

  public static String a(byte[] paramArrayOfByte)
  {
    int i = a(paramArrayOfByte);
    return a(i);
  }

  public static void a(String paramString, MessageDigest paramMessageDigest)
  {
    byte[] arrayOfByte;
    try
    {
      arrayOfByte = paramString.getBytes("Cp1252");
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      throw new alS(localUnsupportedEncodingException);
    }
    paramMessageDigest.update(arrayOfByte);
  }

  public static void a(InputStream paramInputStream, OutputStream paramOutputStream)
  {
    try
    {
      byte[] arrayOfByte = new byte[65536];
      for (int i = paramInputStream.read(arrayOfByte); i > 0; i = paramInputStream.read(arrayOfByte)) {
        paramOutputStream.write(arrayOfByte, 0, i);
      }
    }
    finally
    {
      paramOutputStream.flush();
    }
  }

  public static alU a(InputStream paramInputStream, boolean paramBoolean, MessageDigest paramMessageDigest1, MessageDigest paramMessageDigest2)
  {
    alU localalU = new alU();

    String str1 = a();
    String str2 = b();

    ajB localajB = null;
    StringBuilder localStringBuilder = new StringBuilder();
    Object localObject;
    try
    {
      BufferedReader localBufferedReader = a(paramInputStream);
      for (localObject = localBufferedReader.readLine(); localObject != null; localObject = localBufferedReader.readLine())
      {
        int i = ((String)localObject).indexOf('=');
        if (i < 0)
        {
          if (((String)localObject).length() != 80) {
            localStringBuilder = new StringBuilder();
          } else {
            localStringBuilder.append((String)localObject);
          }
          a((String)localObject, paramMessageDigest1);
        }
        else
        {
          localStringBuilder = new StringBuilder();

          String str4 = ((String)localObject).substring(0, i);
          String str5 = ((String)localObject).substring(i + 1);
          if ((str4.equals(str1)) || (str4.equals(str2)))
          {
            localajB = ajB.b(str5);
          }
          else
          {
            a((String)localObject, paramMessageDigest1);
            a((String)localObject, paramMessageDigest2);
            localalU.a(str4, str5);
          }
        }
      }
    }
    catch (IOException localIOException1)
    {
      throw new alS(localIOException1);
    }
    if ((paramBoolean) && (localStringBuilder.length() > 0))
    {
      String str3 = RH.a(localStringBuilder.toString(), "0", false, true);
      try
      {
        localObject = ajB.c(str3);
      }
      catch (IOException localIOException2)
      {
        throw new alT();
      }
      localalU.b((ajB)localObject);
    }
    else if ((!paramBoolean) && (localajB != null))
    {
      localalU.a(localajB);
    }
    else
    {
      throw new alT();
    }
    return localalU;
  }

  public alW(@NotNull ajB paramajB1, @NotNull ajB paramajB2, boolean paramBoolean)
  {
    this.jdField_a_of_type_SmartgitAjB = paramajB1;
    this.b = paramajB2;
    this.jdField_a_of_type_Boolean = paramBoolean;
  }

  public QY a(akf paramakf)
  {
    try
    {
      ZipInputStream localZipInputStream = new ZipInputStream(paramakf.createStream());localObject1 = null;
      try
      {
        for (ZipEntry localZipEntry = localZipInputStream.getNextEntry(); localZipEntry != null; localZipEntry = localZipInputStream.getNextEntry())
        {
          String str = localZipEntry.getName();
          int i = str.lastIndexOf('/');
          if (i <= 1) {
            try
            {
              return a(new akI(localZipInputStream));
            }
            catch (alS localalS) {}
          }
        }
      }
      catch (Throwable localThrowable2)
      {
        localObject1 = localThrowable2;throw localThrowable2;
      }
      finally
      {
        if (localZipInputStream != null) {
          if (localObject1 != null) {
            try
            {
              localZipInputStream.close();
            }
            catch (Throwable localThrowable6)
            {
              ((Throwable)localObject1).addSuppressed(localThrowable6);
            }
          } else {
            localZipInputStream.close();
          }
        }
      }
    }
    catch (IOException localIOException) {}
    InputStream localInputStream = paramakf.createStream();Object localObject1 = null;
    try
    {
      return a(localInputStream);
    }
    catch (Throwable localThrowable3)
    {
      localObject1 = localThrowable3;throw localThrowable3;
    }
    finally
    {
      if (localInputStream != null) {
        if (localObject1 != null) {
          try
          {
            localInputStream.close();
          }
          catch (Throwable localThrowable7)
          {
            ((Throwable)localObject1).addSuppressed(localThrowable7);
          }
        } else {
          localInputStream.close();
        }
      }
    }
  }

  public alU a(InputStream paramInputStream)
  {
    MessageDigest localMessageDigest1 = a();
    MessageDigest localMessageDigest2 = a();
    alU localalU = a(paramInputStream, this.jdField_a_of_type_Boolean, localMessageDigest1, localMessageDigest2);
    ajB localajB1 = localalU.b();
    ajB localajB2 = localalU.a();
    ajB localajB3;
    if ((this.jdField_a_of_type_Boolean) && (localajB1 != null))
    {
      localajB3 = a(localajB1, this.jdField_a_of_type_SmartgitAjB, this.b);
      a(localajB3, localMessageDigest2);
    }
    else if ((!this.jdField_a_of_type_Boolean) && (localajB2 != null))
    {
      localajB3 = a(localajB2, this.jdField_a_of_type_SmartgitAjB, this.b);
      a(localajB3, localMessageDigest1);
    }
    else
    {
      throw new alT();
    }
    return localalU;
  }

  @NotNull
  private static ajB a(ajB paramajB1, ajB paramajB2, ajB paramajB3)
  {
    synchronized (jdField_a_of_type_JavaUtilMap)
    {
      QX localQX = new QX(paramajB1, paramajB2, paramajB3);
      ajB localajB = (ajB)jdField_a_of_type_JavaUtilMap.get(localQX);
      if (localajB == null)
      {
        localajB = ajB.a(paramajB1, new QY(paramajB2, paramajB3));
        jdField_a_of_type_JavaUtilMap.put(localQX, localajB);
      }
      ajB tmp70_66 = localajB;
      if (tmp70_66 == null) {
        throw new IllegalStateException(String.format("@NotNull method must not return null", new Object[0]));
      }
      return tmp70_66;
    }
  }

  private QY a(InputStream paramInputStream)
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(32768);
    alU localalU = a(new akD(paramInputStream, localByteArrayOutputStream));
    return new QY(localalU, localByteArrayOutputStream.toByteArray());
  }

  private static int a(byte[] paramArrayOfByte)
  {
    if (paramArrayOfByte.length < 8) {
      return 1;
    }
    if (!new String(paramArrayOfByte, 0, 7).equals("Format=")) {
      return 1;
    }
    return paramArrayOfByte[7] - 48;
  }

  private static String a(int paramInt)
  {
    if (paramInt == 1) {
      return "ISO-8859-1";
    }
    return "UTF-8";
  }
}
